#include <iostream>
#include <iomanip>

using namespace std;

/*
题目：输入一个矩阵，按照从外向里以顺时针的顺序依次打印出每一个数字。

例如：如果输入如下矩阵：

1	2   3   4
5   6   7   8
9   10  11  12
13  14	15  16

则依次打印出数字1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10。
*/

template<typename T>
struct Matrix {
	int n;
	T* m;

	public:
	Matrix(int n) : n(n) {
		m = new T[n * n];
		fill(m, m + n*n, 0);
	}

	void Set(int i, int j, T t) {
		m[i * n + j] = t;
	}

	const T& Get(int i, int j) const {
		return m[i * n + j];
	}

};

//迭代版本
void PrintMatrix(const Matrix<int>& matrix) {
	cout << "矩阵: >>>>>>>" << endl;
	for (int i = 0; i < matrix.n; ++i) {
		for (int j = 0; j < matrix.n; ++j) {
			cout << setw(5) << matrix.Get(i, j);
		}
		cout << endl;
	}
	cout << "<<<<<<<<<<<<<" << endl;

	int n = matrix.n;
	int startX = 0, startY = 0; //每次打印的起点
	int NumPerEdge = n - 1; //最外面一层，分成四条边，第条边要打印的个数,每向里一层，个数减2
	int Level = (n+1) / 2;//层数

	cout << "顺时针打印结果如下: >>>>>>" << endl;
	for (int k = 0; k < Level; ++k, NumPerEdge -= 2) {
		startX = startY = k;
		for (startY = k; startY < k + NumPerEdge; ++startY) {
			cout << setw(3) <<  matrix.Get(startX,startY);
		}
		//cout << "\tstartX: " << startX << " startY: " << startY << endl;
		for (startX = k; startX < k + NumPerEdge; ++startX) {
			cout << setw(3) <<  matrix.Get(startX,startY);
		}
		//cout << "\tstartX: " << startX << " startY: " << startY << endl;
		for (startY = startX; startY > k; startY--) {
			cout << setw(3) << matrix.Get(startX,startY);
		}
		//cout << "\tstartX: " << startX << " startY: " << startY << endl;
		for (startX = n - 1 - startY; startX > k; startX--) {
			cout << setw(3) << matrix.Get(startX,startY);
		}
		//cout << "\tstartX: " << startX << " startY: " << startY << endl;
	}
	if (n % 2 == 1) {
		cout << setw(3) << matrix.Get(startX,startY);
	}
	cout << "\n<<<<<<<<<<<<<<<<<<<<<<<<<<" << endl;


}

int main() {

	int n, m;
	cin >> n;

	Matrix<int> matrix(n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> m;
			matrix.Set(i, j, m);	
		}
	}

	PrintMatrix(matrix);

	return 0;
}
